package com.woniuxy.commons.util;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayFundTransToaccountTransferRequest;
import com.alipay.api.response.AlipayFundTransToaccountTransferResponse;
import com.woniuxy.commons.config.AlipayConfig;
import com.woniuxy.commons.param.TransfesInfo;

public class TransferUtil {

    public static Result<String> Transfer(TransfesInfo transfesInfo) throws AlipayApiException {

        AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl,AlipayConfig.app_id,AlipayConfig.merchant_private_key,"json",AlipayConfig.charset,AlipayConfig.alipay_public_key,"RSA2");

        AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest();
        request.setBizContent("{" +
                "  \"out_biz_no\":\""+TransferOrderRandom.createOrderSnRandom()+"\"," +
                "  \"payee_type\":\"ALIPAY_LOGONID\"," +
                "  \"payee_account\":\""+transfesInfo.getPayee_account()+"\"," +
                "  \"amount\":\""+transfesInfo.getAmount()+"\"," +
//                "  \"payer_real_name\":\"2088621958215041\"," +
//                "  \"payer_show_name\":\"测试\"," +
//                "  \"payee_real_name\":\"tgtygr0268\"," +
                "  \"remark\":\""+transfesInfo.getRemark()+"\"," +
                "  \"ext_param\":\"{\\\"order_title\\\":\\\""+transfesInfo.getOrder_title()+"\\\"}\"" +
                "}");
        AlipayFundTransToaccountTransferResponse response = alipayClient.execute(request);
        if(response.isSuccess()){
            System.out.println("转账唯一订单号"+response.getOutBizNo());
            System.out.println("调用成功");
            return  Result.getInstance(String.class).setCode(200).setData(response.getOutBizNo()).setMsg("转账成功");
        } else {
            System.out.println("调用失败");
            return  Result.getInstance(String.class).setCode(500).setMsg("转账失败");
        }
    }

}


